package com.dominator.api.controller;

import com.dominator.api.annotation.UserLoginToken;
import com.dominator.api.common.WebCxt;
import com.dominator.api.common.wrapper.Dto;
import com.dominator.api.enums.ReqEnums;
import com.dominator.api.service.DemoService;
import com.dominator.api.utils.api.ApiMessage;

import com.google.gson.Gson;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/api/v1/demo")
public class DemoController {

    @Autowired
    DemoService demoService;


    @Autowired
    HttpServletRequest request;


    @RequestMapping("/test")
    public String test(){
        return "test!!!!!!!!!!!!!";
    }


    @RequestMapping("/createUser")
    @UserLoginToken
    public String  createUser(){
        ApiMessage apiMessage=new ApiMessage(ReqEnums.REQ_SUCCESS);
        try {
            Dto dto= WebCxt.getParamAsDto(request);
            demoService.createUser(dto);
        }catch (Exception e){
            apiMessage=new ApiMessage(ReqEnums.REQ_ERROR);
        }
        return new Gson().toJson(apiMessage);
    }



}
